package cn.hinglo.common.handler;

import cn.hinglo.common.constant.SystemConstant;
import com.jfinal.handler.Handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @createTime: 2018/7/24
 * @author: HingLo
 * @description: 开发测试阶段的跨域处理
 */
public class CorsHandler extends Handler {
    @Override
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
        // 指定来源
        response.setHeader("Access-Control-Allow-Origin", "*");
        // 指定请求允许的方式
        response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Allow-Headers", SystemConstant.ALLOW_HEADER);
        response.setHeader("Access-Control-Allow-Credentials", "true");
        next.handle(target, request, response, isHandled);
    }
}
